package cs271.examples.sorting;

import java.util.Random;

/**
 * An example of the Bubble Sort algorithm.  Bubblesort
 * is a poor sorting algorithm of O(n^2).
 */
public class IntBubbleSort {
    
    private static final int ARRAY_SIZE = 100;
    
    public static void printIntArray(int[] array) {
    	int count =  0;
    	for(int i: array) {
    		System.out.print(i + " ");
    		if(count == 10) {
    			System.out.println();
    			count = 0;
    		} else {
    			count++;
    		}
    	}
    }
    
    public static void bubbleSort(int[] list) {
    	int temp=0;
        for(int i=0; i<list.length; i++) {
            for(int j =0;j < list.length -i -1; j++) {
                if (list[j] > list[j+1]) {
                    temp = list[j+1];
                    list[j+1] = list[j];
                    list[j] = temp;
                }
            }
        }
    }
    
    public static void main(String[] args) {
        int [] list=new int [ARRAY_SIZE];
        
        //initialize the array with random variables
        Random R=new Random();
        for(int i=0; i<list.length; i++) {
            list[i]=R.nextInt(50000);
        }
        
        bubbleSort(list);
        
        printIntArray(list);
    }
}